package com.fgs.common.textWatcher;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.EditText;

import com.fgs.common.utils.CheckUtil;
import com.fgs.common.utils.ToastUtil;


/**
 * @author fgs
 * @date 2020/5/16
 * @description
 **/

public class InputTextWatcher implements TextWatcher {
    private EditText editText;

    public InputTextWatcher(EditText editText) {
        this.editText = editText;
    }


    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable edt) {
        String temp = edt.toString();
        if (TextUtils.isEmpty(temp)) return;
        if (CheckUtil.isEmoji(temp)) {
            edt.delete(edt.length() - 2, edt.length());
            ToastUtil.showShortToast("不能输入表情符号");
//        } else if (!TextUtils.isEmpty(temp) && !CheckUtil.isInputLimit(temp)) {
        } else if (!TextUtils.isEmpty(temp) && !CheckUtil.isInputLimit(temp)) {
            edt.delete(edt.length() - 1, edt.length());
            ToastUtil.showShortToast("不能输入非法字符");
        }


    }

}
